import { Controller, Post, Body } from '@nestjs/common';
import { CreateUserDto } from './dto/user.dto';
import { UserService } from './user.service';
import { User } from './entities/user.entity';
import { AuthService } from '../auth/auth.service';

@Controller('user')
export class UserController {
  constructor(
    private readonly userService: UserService,
    private readonly authService: AuthService,
  ) {}

  @Post('register')
  async register(@Body() CreateUserDto: CreateUserDto): Promise<User> {
    console.log(CreateUserDto, 'CreateUserDto');
    const { username, password } = CreateUserDto;
    return this.userService.createUser(username, password);
  }

  @Post('login')
  async login(@Body() CreateUserDto: CreateUserDto) {
    const { username, password } = CreateUserDto;
    return this.authService.login({ username, password });
  }
}
